package com.mall.service;


import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.api.OmsOrderReturnReasonApi;
import com.mall.pageResult.PageResult;
import com.mall.pojo.OmsOrderReturnReason;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OmsOrderReturnReasonService {

    @DubboReference
    private OmsOrderReturnReasonApi omsOrderReturnReasonApi;

    //添加用户退货原因
    public Integer createOrderReturnReason(OmsOrderReturnReason omsOrderReturnReason) {
        //调用Api进行添加
       Integer createNum =  omsOrderReturnReasonApi.createOrderReturnReason(omsOrderReturnReason);
   return createNum;
    }
    //分页查询操作
    public PageResult<OmsOrderReturnReason> findOrderReturnReasonList(Integer pageNum, Integer pageSize) {
        //调用Api进行分页查询
        Page<OmsOrderReturnReason> page = omsOrderReturnReasonApi.findOrderReturnReasonList(pageNum,pageSize);
        PageResult<OmsOrderReturnReason> pageRe = new PageResult<>();
        pageRe.setPageNum(pageNum);
        pageRe.setPageSize(pageSize);
        pageRe.setList(page.getRecords());
        //result.setTotalPage(Convert.toInt(Math.ceil(promotions.size() / pageSize))); //向上取整
        pageRe.setTotalPage(Convert.toInt(page.getPages()));
        pageRe.setTotal(Convert.toInt(page.getTotal()));
        return pageRe;
    }

    /**
     * 根据id信息回显
     * @param id
     * @return
     */
    public OmsOrderReturnReason findOrderInfoById(Integer id) {
        //调用Api中的方法进行查询
       OmsOrderReturnReason osR =  omsOrderReturnReasonApi.findOrderInfoById(id);
       return osR;
    }

    /**
     * 删除单个或者批量删除功能
     * @param ids
     */
    public Integer deleteOrderReturnReasonByIds(List<Integer> ids) {
        //调用api进行删除操作
       Integer deleteNum =  omsOrderReturnReasonApi.deleteOrderReturnReasonByIds(ids);
    //返回受影响行数
        return deleteNum;

    }

    /**
     * 对用户退货原因进行修改
     * @param omsOrderReturnReason
     * @return
     */
    public Integer updateOrderInfoReturn(OmsOrderReturnReason omsOrderReturnReason) {
        //调用方法进行修改
        Integer updateNum = omsOrderReturnReasonApi.updateOrderInfoReturn(omsOrderReturnReason);
        return updateNum;
    }

    /**
     *修改退货原因信息的状态
     * @param ids
     * @param status
     * @return
     */

    public Integer updateOrderInfoReturnStatus(List<Integer> ids, Integer status) {
        //调用方法进行修改
        Integer updateNum = omsOrderReturnReasonApi.updateOrderInfoReturnStatus(ids,status);
        return updateNum;


    }
}
